package com.tang.algorithm.swordFingerOffer;

/**
 * @author tlm
 * @version 1.0
 * @date 2020/5/2 17:13
 * 调整数组顺序使奇数位于偶数前面
 * <p>
 * https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/
 */
public class AdjustArrayOrder {
    public static void main(String[] args) {
        int[] a = {1, 2, 3, 4};
        int []res = exchange(a);
        for (int i = 0; i <res.length ; i++) {
            System.out.println(res[i]);
        }
    }

    public static int[] exchange(int[] nums) {
        int[] res = new int[nums.length];
        int l = 0, r = nums.length - 1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] % 2 == 1) {
                res[l] = nums[i];
                l++;
            } else {
                res[r] = nums[i];
                r--;
            }
        }
        return res;

    }
}
